package com.yDev.imagemaker;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import com.yDev.imagemaker.ColorPickerDialog.OnColorChangedListener;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;

public class Launcher extends Activity {
	
	mCusView mView;
	ColorPickerDialog cp;
	OnColorChangedListener colorChangedListener;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // making it full screen
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        mView= new mCusView(getApplicationContext());
        colorChangedListener= new OnColorChangedListener() {
			
			@Override
			public void colorChanged(int color) {
				mView.setColor(color);
			}
		};
        cp=new ColorPickerDialog(this, colorChangedListener, Color.WHITE);
        
        setContentView(mView);
	}
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
 
    public boolean saveClicked(MenuItem item) {
    	String mScreenshotPath = Environment.getExternalStorageDirectory()+"";
 	   Bitmap bitmap = Bitmap.createBitmap(mView.getWidth(), mView.getHeight(), Bitmap.Config.ARGB_8888);
 	   mView.onDraw(new Canvas(bitmap));
 	   try {
 	       OutputStream out = new BufferedOutputStream(new FileOutputStream(mScreenshotPath + "/imageMaker/" + System.currentTimeMillis() + ".jpg"));
 	       bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
 	   } catch (IOException e) {
 	      // Log.w(TAG, e);
 	   }
    	
        return true;
    }
    
    public boolean pickColorClicked(MenuItem item) {
    	
    	cp.show();
    	
        return true;
    }
}
